package com.har.modules.business.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.toolkit.StringUtils;
import com.har.common.utils.PageUtils;
import com.har.common.utils.Query;
import com.har.modules.business.dao.TRegisterDao;
import com.har.modules.business.entity.TRegisterEntity;
import com.har.modules.business.service.TRegisterService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


@Service("tRegisterService")
public class TRegisterServiceImpl extends ServiceImpl<TRegisterDao, TRegisterEntity> implements TRegisterService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {

        EntityWrapper<TRegisterEntity> ew = new EntityWrapper<>();
        if(StringUtils.checkValNotNull(params.get("productTypeName"))){
            ew.eq("product_type_Name",params.get("productTypeName"));
        }

        if(StringUtils.checkValNotNull(params.get("productName"))){
            ew.eq("product_name",params.get("productName"));
        }


        if(StringUtils.checkValNotNull(params.get("date"))){
            String[] dates = params.get("date").toString().split("~");
            ew.gt("create_time",dates[0]+" 00:00:00");
            ew.lt("create_time",dates[1]+" 23:59:59");
        }


        Page<TRegisterEntity> page = this.selectPage(
                new Query<TRegisterEntity>(params).getPage(),
               ew
        );

        return new PageUtils(page);
    }

    @Override
    public List<TRegisterEntity> export(Map<String, Object> params) {

        EntityWrapper<TRegisterEntity> ew = new EntityWrapper<>();
        if(StringUtils.checkValNotNull(params.get("productTypeName"))){
            ew.eq("productTypeName",params.get("productTypeName"));
        }

        if(StringUtils.checkValNotNull(params.get("productName"))){
            ew.eq("productName",params.get("productName"));
        }


        if(StringUtils.checkValNotNull(params.get("date"))){
            String[] dates = params.get("date").toString().split("~");
            ew.gt("create_time",dates[0]+" 00:00:00");
            ew.lt("create_time",dates[1]+" 23:59:59");
        }

        return  selectList(ew);
    }
}
